<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>公式设置</title>
    <link rel="stylesheet" href="/static/component/pear/css/pear.css"/>
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
    <script src="/static/component/pear/module/ruinuo/sortable.js"></script>
    <script src="/static/component/pear/module/ruinuo/xm-select.js"></script>
</head>
<body>
<div class="view_body">
    <form class="layui-form" action="">
        <div class="ruinuo_box">
            <div class="main-container layui-row layui-col-space10 form_top label_con">

                <blockquote class="layui-elem-quote tips_legend layui-col-xs12">事件设置只支持单选框、下拉单选框、数字输入框</blockquote>

                <div class="layui-col-xs12 layui-col-md12">
                    <textarea name="gongshi_txt" id="focus_1712541319_7" class="layui-textarea" style="height: 60px"></textarea>
                </div>


                <div class="layui-col-xs12 layui-col-md12">
                    <label class="layui-form-label">运算公式</label>
                    <div class="layui-input-block">
                        <div class="layui-btn-group gongshi_curd">
                            <button type="button" data-val="+" class="layui-btn layui-btn-sm" onclick="JiSuan(this)">加法</button>
                            <button type="button" data-val="-" class="layui-btn layui-btn-sm" onclick="JiSuan(this)">减法</button>
                            <button type="button" data-val="*" class="layui-btn layui-btn-sm" onclick="JiSuan(this)">乘法</button>
                            <button type="button" data-val="/" class="layui-btn layui-btn-sm" onclick="JiSuan(this)">除法</button>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-md12">
                    <label class="layui-form-label">字段数据</label>
                    <div class="layui-input-block">
                        <div class="layui-btn-group gongshi_field">
                        </div>
                    </div>
                </div>


            </div>
        </div>

    </form>

</div>

<script>

    let $ = layui.jquery;
    layui.use(['form', 'http', 'public', 'engine_form'], function () {
        init();
    })

    function init() {
        let data = $(".design-right-con input[name='gongshi_txt']", window.parent.document).val() || '';
        $("#focus_1712541319_7").val(data);
        let fields=parent.layui.design_form.GetFieldData();
        let gongshi_field='';
        fields.forEach(item=>{
            if (item.tag=='input' || item.tag=='select' || item.tag=='radio')
            {
                gongshi_field+='<button type="button" data-val="{'+item.field+'}" class="layui-btn layui-btn-sm" onclick="JiSuan(this)">'+item.title+'</button>';
            }
        })
        $(".gongshi_field").html(gongshi_field);
    }
    function JiSuan(obj)
    {
        let val=$("#focus_1712541319_7").val()+$(obj).attr('data-val');
        $("#focus_1712541319_7").val(val);
    }
    function SendForm() {
        let val = $("#focus_1712541319_7").val();
        if (val == '') {
            layui.layer.msg('规则设置不能为空', {icon: 2});
            return false;
        }
        return val;
    }
</script>
</body>
</html>

